package com.geovis.emergency.spd.biz.basic.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geovis.emergency.spd.biz.basic.mapper.BasicPunchRuleMapper;
import com.geovis.emergency.spd.biz.basic.service.IBasicPunchRuleService;
import com.geovis.emergency.spd.entity.basic.entity.BasicPunchRule;
import com.geovis.emergency.spd.entity.basic.pojo.dto.BasicPunchRuleQueryDTO;
import com.geovis.emergency.spd.entity.basic.pojo.dto.BasicPunchRuleSaveDTO;
import com.geovis.emergency.spd.entity.basic.pojo.dto.BasicPunchRuleUpdateDTO;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
 * <p>
 * 基础模块--打卡规则表 服务实现类
 * </p>
 *
 * @author lmolong
 * @since 2022-06-21
*/

@Service
@RequiredArgsConstructor
@Slf4j
public class BasicPunchRuleServiceImpl extends ServiceImpl<BasicPunchRuleMapper, BasicPunchRule> implements IBasicPunchRuleService {

    @Override
    public BasicPunchRule getByPcDrillId(String userId, String pcDrillId) {
        return baseMapper.getByPcDrillId(userId,pcDrillId);
    }
    @Override
    public LambdaQueryWrapper<BasicPunchRule> getWrapper(BasicPunchRuleQueryDTO queryDTO) {
        //创建查询条件
        LambdaQueryWrapper<BasicPunchRule> wrapper = Wrappers.lambdaQuery(BasicPunchRule.class).orderByDesc(BasicPunchRule::getId);
        if (ObjectUtil.isNotEmpty(queryDTO)) {
            wrapper.like(ObjectUtil.isNotEmpty(queryDTO.getAddress()), BasicPunchRule::getAddress, queryDTO.getAddress())
                    .eq(ObjectUtil.isNotEmpty(queryDTO.getBasicDutyPostId()), BasicPunchRule::getBasicDutyPostId, queryDTO.getBasicDutyPostId());
        }
        return wrapper;
    }

    @Override
    public void saveBasicPunchRule(BasicPunchRuleSaveDTO saveDTO) {
        BasicPunchRule basicPunchRule=new BasicPunchRule();
        BeanUtil.copyProperties(saveDTO,basicPunchRule);
        this.save(basicPunchRule);
    }

    @Override
    public void updateByIdBasicPunchRule(BasicPunchRuleUpdateDTO updateDTO) {
        BasicPunchRule basicPunchRule=new BasicPunchRule();
        BeanUtil.copyProperties(updateDTO,basicPunchRule);
        this.updateById(basicPunchRule);
    }
}
